﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class Customer : BasePage
    {
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected Button btnSaveAuthorizedUser;
        protected CheckBox chkIsActive;
        protected CheckBox chkSameAsAddress;
        protected HtmlGenericControl divL5;
        protected HtmlGenericControl divR5;
        protected HtmlForm F2021;
        protected HtmlInputHidden hdnAuthorizedUser;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnUnauthorizedUser;
        protected HtmlHead Head1;
        protected ImageButton imgAuthorizedUser;
        protected ImageButton imgUnauthorizedUser;
        protected Label lbCustomerID;
        protected Label lblAddress;
        protected Label lblAuthorizedUser;
        protected Label lblBillAddress;
        protected Label lblBillCity;
        protected Label lblBillContact1;
        protected Label lblBillContact2;
        protected Label lblBillCountry;
        protected Label lblBillEmail1;
        protected Label lblBillEmail2;
        protected Label lblBillFax1;
        protected Label lblBillFax2;
        protected Label lblBillPhone1;
        protected Label lblBillPhone2;
        protected Label lblBillProvince;
        protected Label lblBillZip;
        protected Label lblCity;
        protected Label lblContact1;
        protected Label lblContact2;
        protected Label lblCountry;
        protected Label lblCustomerName;
        protected Label lblDescr;
        protected Label lblEmail1;
        protected Label lblEmail2;
        protected Label lblFax1;
        protected Label lblFax2;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblPhone1;
        protected Label lblPhone2;
        protected Label lblProvince;
        protected Label lblRemark;
        protected Label lblUnauthorizedUser;
        protected Label lblUserDefine1;
        protected Label lblUserDefine10;
        protected Label lblUserDefine2;
        protected Label lblUserDefine3;
        protected Label lblUserDefine4;
        protected Label lblUserDefine5;
        protected Label lblUserDefine6;
        protected Label lblUserDefine7;
        protected Label lblUserDefine8;
        protected Label lblUserDefine9;
        protected Label lblVAT;
        protected Label lblZip;
        protected ListBox lbxAuthorizedUser;
        protected ListBox lbxUnauthorizedUser;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected ScriptManager ScriptManager1;
        public static int TabNum = 5;
        protected TextBox txtAddress;
        protected TextBox txtBillAddress;
        protected TextBox txtBillCity;
        protected TextBox txtBillConatact2;
        protected TextBox txtBillContact1;
        protected TextBox txtBillCountry;
        protected TextBox txtBillEmail1;
        protected TextBox txtBillEmail2;
        protected TextBox txtBillFax1;
        protected TextBox txtBillFax2;
        protected TextBox txtBillPhone1;
        protected TextBox txtBillPhone2;
        protected TextBox txtBillProvince;
        protected TextBox txtBillZIP;
        protected TextBox txtCity;
        protected TextBox txtConatact2;
        protected TextBox txtContact1;
        protected TextBox txtCountry;
        protected TextBox txtCustomerID;
        protected TextBox txtCustomerName;
        protected TextBox txtEmail1;
        protected TextBox txtEmail2;
        protected TextBox txtFax1;
        protected TextBox txtFax2;
        protected TextBox txtPhone1;
        protected TextBox txtPhone2;
        protected TextBox txtProvince;
        protected TextBox txtRemark;
        protected TextBox txtUserDefine1;
        protected TextBox txtUserDefine10;
        protected TextBox txtUserDefine2;
        protected TextBox txtUserDefine3;
        protected TextBox txtUserDefine4;
        protected TextBox txtUserDefine5;
        protected TextBox txtUserDefine6;
        protected TextBox txtUserDefine7;
        protected TextBox txtUserDefine8;
        protected TextBox txtUserDefine9;
        protected TextBox txtVAT;
        protected TextBox txtVendorDescr;
        protected TextBox txtZIP;
        protected UpdatePanel up1;

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtCustomerID.Text = "";
            this.txtCustomerID.Enabled = true;
            this.txtCustomerName.Text = "";
            this.txtCustomerName.Enabled = true;
            base.DataEntityViewState = null;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()) && !string.IsNullOrEmpty(this.txtCustomerName.Text.Trim()))
            {
                try
                {
                    List<string> customerID = new List<string> {
                        this.txtCustomerID.Text.Trim()
                    };
                    this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Delete(customerID, "CUSTOMER") + base.GetGlobalMsgResource("C006");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                    base.DataEntityViewState = null;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("CustomerQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("CustomerList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2120_001");
            }
            else if (string.IsNullOrEmpty(this.txtCustomerName.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2120_002");
            }
            else
            {
                if (base.DataEntityViewState != null)
                {
                    this.UpdateCustomerInfo();
                }
                else
                {
                    this.InsertCustomerInfo();
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',1," + TabNum + ") </script>", false);
            }
        }

        protected void btnSaveAuthorizedUser_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2120_001");
            }
            else if (this.txtCustomerID.Enabled)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2120_006");
            }
            else
            {
                string authorizationUser = string.Empty;
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                if ((dtUser != null) && (dtUser.Rows.Count > 0))
                {
                    for (int i = 0; i < dtUser.Rows.Count; i++)
                    {
                        if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "Y")
                        {
                            authorizationUser = authorizationUser + dtUser.Rows[i]["USER_ID"].ToString() + ";";
                        }
                    }
                }
                if (authorizationUser.Length > 1)
                {
                    try
                    {
                        authorizationUser = authorizationUser.Substring(0, authorizationUser.Length - 1);
                        if (CommoneMethodServiceClientProxy.GetInstance().UpdateAuthorizationUserByType(authorizationUser, "CUSTOMER", this.txtCustomerID.Text.Trim()) > 0)
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2120_003");
                        }
                        else
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2120_004");
                        }
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = ex.Message;
                        return;
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F2120_005");
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5," + TabNum + ");$.unblockUI(); </script>", false);
            }
        }

        protected void chkSameAsAddress_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkSameAsAddress.Checked)
            {
                this.txtBillCity.Text = this.txtCity.Text;
                this.txtBillProvince.Text = this.txtProvince.Text;
                this.txtBillContact1.Text = this.txtContact1.Text;
                this.txtBillConatact2.Text = this.txtConatact2.Text;
                this.txtBillCountry.Text = this.txtCountry.Text;
                this.txtBillZIP.Text = this.txtZIP.Text;
                this.txtBillPhone1.Text = this.txtPhone1.Text;
                this.txtBillPhone2.Text = this.txtPhone2.Text;
                this.txtBillAddress.Text = this.txtAddress.Text;
                this.txtBillFax1.Text = this.txtFax1.Text;
                this.txtBillFax2.Text = this.txtFax2.Text;
                this.txtBillEmail1.Text = this.txtEmail1.Text;
                this.txtBillEmail2.Text = this.txtEmail2.Text;
                ScriptManager.RegisterStartupScript((Page) this, base.GetType(), "", "<script language='JavaScript'>setTab('one',3," + TabNum + ");</script>", false);
            }
        }

        protected void imgAuthorizedUser_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedUser.Value))
            {
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                string[] strAuthorizedUser = this.hdnAuthorizedUser.Value.Split(new char[] { ';' });
                for (int i = 0; i < dtUser.Rows.Count; i++)
                {
                    if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "Y")
                    {
                        for (int j = 0; strAuthorizedUser.Length > j; j++)
                        {
                            if (dtUser.Rows[i]["USER_ID"].ToString() == strAuthorizedUser[j])
                            {
                                dtUser.Rows[i]["PREMISSION_USER"] = "N";
                                break;
                            }
                        }
                    }
                }
                base.PageQueryEntitySession = dtUser;
                this.hdnAuthorizedUser.Value = string.Empty;
                this.SetControlslbxUserData(dtUser);
            }
            if (this.lbxUnauthorizedUser.Items.Count > 0)
            {
                this.lbxUnauthorizedUser.Items[0].Selected = true;
                this.lbxUnauthorizedUser_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5," + TabNum + ") </script>", false);
        }

        protected void imgUnauthorizedUser_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedUser.Value))
            {
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                string[] strUnauthorizedUser = this.hdnUnauthorizedUser.Value.Split(new char[] { ';' });
                for (int i = 0; i < dtUser.Rows.Count; i++)
                {
                    if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "N")
                    {
                        for (int j = 0; strUnauthorizedUser.Length > j; j++)
                        {
                            if (dtUser.Rows[i]["USER_ID"].ToString() == strUnauthorizedUser[j])
                            {
                                dtUser.Rows[i]["PREMISSION_USER"] = "Y";
                                break;
                            }
                        }
                    }
                }
                base.PageQueryEntitySession = dtUser;
                this.hdnUnauthorizedUser.Value = string.Empty;
                this.SetControlslbxUserData(dtUser);
            }
            if (this.lbxAuthorizedUser.Items.Count > 0)
            {
                this.lbxAuthorizedUser.Items[0].Selected = true;
                this.lbxAuthorizedUser_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5," + TabNum + ") </script>", false);
        }

        private void InsertCustomerInfo()
        {
            try
            {
                CustomerInfo customerInfo = new CustomerInfo {
                    CustomerID = this.txtCustomerID.Text.Trim(),
                    Company = this.txtCustomerName.Text.Trim(),
                    Description = this.txtVendorDescr.Text.Trim(),
                    Vat = this.txtVAT.Text.Trim(),
                    IsActive = this.chkIsActive.Checked ? "Y" : "N",
                    CreatedBy = base.UserInfo.UserID,
                    City = this.txtCity.Text.Trim(),
                    State = this.txtProvince.Text.Trim(),
                    Contact1 = this.txtContact1.Text.Trim(),
                    Contact2 = this.txtConatact2.Text.Trim(),
                    Country = this.txtCountry.Text.Trim(),
                    Zip = this.txtZIP.Text.Trim(),
                    Phone1 = this.txtPhone1.Text.Trim(),
                    Phone2 = this.txtPhone2.Text.Trim(),
                    Address = this.txtAddress.Text.Trim(),
                    Fax1 = this.txtFax1.Text.Trim(),
                    Fax2 = this.txtFax2.Text.Trim(),
                    Email1 = this.txtEmail1.Text.Trim(),
                    Email2 = this.txtEmail2.Text.Trim()
                };
                if (this.chkSameAsAddress.Checked)
                {
                    customerInfo.BCity = customerInfo.City;
                    customerInfo.BState = customerInfo.State;
                    customerInfo.BContact1 = customerInfo.Contact1;
                    customerInfo.BContact2 = customerInfo.Contact2;
                    customerInfo.BCountry = customerInfo.Country;
                    customerInfo.BZip = customerInfo.Zip;
                    customerInfo.BPhone1 = customerInfo.Phone1;
                    customerInfo.BPhone2 = customerInfo.Phone2;
                    customerInfo.BAddress = customerInfo.Address;
                    customerInfo.BFax1 = customerInfo.Fax1;
                    customerInfo.BFax2 = customerInfo.Fax2;
                    customerInfo.BEmail1 = customerInfo.Email1;
                    customerInfo.BEmail2 = customerInfo.Email2;
                }
                else
                {
                    customerInfo.BCity = this.txtBillCity.Text.Trim();
                    customerInfo.BState = this.txtProvince.Text.Trim();
                    customerInfo.BContact1 = this.txtBillContact1.Text.Trim();
                    customerInfo.BContact2 = this.txtBillConatact2.Text.Trim();
                    customerInfo.BCountry = this.txtBillCountry.Text.Trim();
                    customerInfo.BZip = this.txtBillZIP.Text.Trim();
                    customerInfo.BPhone1 = this.txtBillPhone1.Text.Trim();
                    customerInfo.BPhone2 = this.txtBillPhone2.Text.Trim();
                    customerInfo.BAddress = this.txtBillAddress.Text.Trim();
                    customerInfo.BFax1 = this.txtBillFax1.Text.Trim();
                    customerInfo.BFax2 = this.txtBillFax2.Text.Trim();
                    customerInfo.BEmail1 = this.txtBillEmail1.Text.Trim();
                    customerInfo.BEmail2 = this.txtBillEmail2.Text.Trim();
                }
                customerInfo.Udf1 = this.txtUserDefine1.Text.Trim();
                customerInfo.Udf2 = this.txtUserDefine2.Text.Trim();
                customerInfo.Udf3 = this.txtUserDefine3.Text.Trim();
                customerInfo.Udf4 = this.txtUserDefine4.Text.Trim();
                customerInfo.Udf5 = this.txtUserDefine5.Text.Trim();
                customerInfo.Udf6 = this.txtUserDefine6.Text.Trim();
                customerInfo.Udf7 = this.txtUserDefine7.Text.Trim();
                customerInfo.Udf8 = this.txtUserDefine8.Text.Trim();
                customerInfo.Udf9 = this.txtUserDefine9.Text.Trim();
                customerInfo.Udf10 = this.txtUserDefine10.Text.Trim();
                customerInfo.Remark = this.txtRemark.Text.Trim();
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Insert(customerInfo, "CUSTOMER") + base.GetGlobalMsgResource("C004");
                base.DataEntityViewState = customerInfo;
                this.txtCustomerID.Enabled = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        protected void lbxAuthorizedUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedUser.Value = "";
            if (this.lbxAuthorizedUser.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedUser.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedUser.Value = this.hdnAuthorizedUser.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedUser.Value))
                {
                    this.hdnAuthorizedUser.Value = this.hdnAuthorizedUser.Value.Substring(0, this.hdnAuthorizedUser.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5," + TabNum + ") </script>", false);
        }

        protected void lbxUnauthorizedUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedUser.Value = "";
            if (this.lbxUnauthorizedUser.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedUser.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedUser.Value = this.hdnUnauthorizedUser.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedUser.Value))
                {
                    this.hdnUnauthorizedUser.Value = this.hdnUnauthorizedUser.Value.Substring(0, this.hdnUnauthorizedUser.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5," + TabNum + ") </script>", false);
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.SetCustomerInfo2Form();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            this.SetAuthorizationUser();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetAuthorizationUser()
        {
            if ((base.UserInfo.IsGlobal == "Y") && (base.UserInfo.IsPremissionsFunctionID == "Y"))
            {
                DataSet userDS = CommoneMethodServiceClientProxy.GetInstance().GetAuthorizationUserByType("CUSTOMER", this.txtCustomerID.Text.Trim());
                if ((userDS != null) && (userDS.Tables[0].Rows.Count > 0))
                {
                    if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                    {
                        for (int i = 0; i < userDS.Tables[0].Rows.Count; i++)
                        {
                            userDS.Tables[0].Rows[i]["PREMISSION_USER"] = "Y";
                        }
                    }
                    this.SetControlslbxUserData(userDS.Tables[0]);
                    base.PageQueryEntitySession = userDS.Tables[0];
                }
                TabNum = 5;
            }
            else
            {
                TabNum = 4;
                this.one5.Visible = false;
                this.divL5.Visible = false;
                this.divR5.Visible = false;
            }
        }

        private void SetControlslbxUserData(DataTable dtUser)
        {
            DataRow[] drAuthorizedUser = dtUser.Select("PREMISSION_USER = 'Y'");
            DataTable dtAuthorizedUser = new DataTable();
            dtAuthorizedUser = dtUser.Clone();
            foreach (DataRow dr in drAuthorizedUser)
            {
                dtAuthorizedUser.ImportRow(dr);
            }
            this.lbxAuthorizedUser.DataSource = dtAuthorizedUser;
            this.lbxAuthorizedUser.DataTextField = "USER_NAME";
            this.lbxAuthorizedUser.DataValueField = "USER_ID";
            this.lbxAuthorizedUser.DataBind();
            DataRow[] drUnauthorizedUser = dtUser.Select("PREMISSION_USER <> 'Y'");
            DataTable dtUnauthorizedUser = new DataTable();
            dtUnauthorizedUser = dtUser.Clone();
            foreach (DataRow dr in drUnauthorizedUser)
            {
                dtUnauthorizedUser.ImportRow(dr);
            }
            this.lbxUnauthorizedUser.DataSource = dtUnauthorizedUser;
            this.lbxUnauthorizedUser.DataTextField = "USER_NAME";
            this.lbxUnauthorizedUser.DataValueField = "USER_ID";
            this.lbxUnauthorizedUser.DataBind();
        }

        private void SetCustomerInfo2Form()
        {
            try
            {
                string CustomerID = base.Request.QueryString["ID"].ToString();
                CustomerInfo Customer = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(CustomerID, "CUSTOMER") as CustomerInfo;
                if (Customer != null)
                {
                    base.DataEntityViewState = Customer;
                    this.txtCustomerID.Text = Customer.CustomerID;
                    this.txtCustomerName.Text = Customer.Company;
                    this.txtVendorDescr.Text = Customer.Description;
                    this.txtVAT.Text = Customer.Vat;
                    this.chkIsActive.Checked = Customer.IsActive == "Y";
                    this.txtCity.Text = Customer.City;
                    this.txtProvince.Text = Customer.State;
                    this.txtContact1.Text = Customer.Contact1;
                    this.txtConatact2.Text = Customer.Contact2;
                    this.txtCountry.Text = Customer.Country;
                    this.txtZIP.Text = Customer.Zip;
                    this.txtPhone1.Text = Customer.Phone1;
                    this.txtPhone2.Text = Customer.Phone2;
                    this.txtAddress.Text = Customer.Address;
                    this.txtFax1.Text = Customer.Fax1;
                    this.txtFax2.Text = Customer.Fax2;
                    this.txtEmail1.Text = Customer.Email1;
                    this.txtEmail2.Text = Customer.Email2;
                    this.txtBillCity.Text = Customer.BCity;
                    this.txtBillProvince.Text = Customer.State;
                    this.txtBillContact1.Text = Customer.BContact1;
                    this.txtBillConatact2.Text = Customer.BContact2;
                    this.txtBillCountry.Text = Customer.BCountry;
                    this.txtBillZIP.Text = Customer.BZip;
                    this.txtBillPhone1.Text = Customer.BPhone1;
                    this.txtBillPhone2.Text = Customer.BPhone2;
                    this.txtBillAddress.Text = Customer.BAddress;
                    this.txtBillFax1.Text = Customer.BFax1;
                    this.txtBillFax2.Text = Customer.BFax2;
                    this.txtBillEmail1.Text = Customer.BEmail1;
                    this.txtBillEmail2.Text = Customer.BEmail2;
                    this.txtUserDefine1.Text = Customer.Udf1;
                    this.txtUserDefine2.Text = Customer.Udf2;
                    this.txtUserDefine3.Text = Customer.Udf3;
                    this.txtUserDefine4.Text = Customer.Udf4;
                    this.txtUserDefine5.Text = Customer.Udf5;
                    this.txtUserDefine6.Text = Customer.Udf6;
                    this.txtUserDefine7.Text = Customer.Udf7;
                    this.txtUserDefine8.Text = Customer.Udf8;
                    this.txtUserDefine9.Text = Customer.Udf9;
                    this.txtUserDefine10.Text = Customer.Udf10;
                    this.txtRemark.Text = Customer.Remark;
                    this.txtCustomerID.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void UpdateCustomerInfo()
        {
            try
            {
                CustomerInfo customerInfo = base.DataEntityViewState as CustomerInfo;
                customerInfo.Company = this.txtCustomerName.Text.Trim();
                customerInfo.Description = this.txtVendorDescr.Text.Trim();
                customerInfo.Vat = this.txtVAT.Text.Trim();
                customerInfo.IsActive = this.chkIsActive.Checked ? "Y" : "N";
                customerInfo.UpdatedBy = base.UserInfo.UserID;
                customerInfo.City = this.txtCity.Text.Trim();
                customerInfo.State = this.txtProvince.Text.Trim();
                customerInfo.Contact1 = this.txtContact1.Text.Trim();
                customerInfo.Contact2 = this.txtConatact2.Text.Trim();
                customerInfo.Country = this.txtCountry.Text.Trim();
                customerInfo.Zip = this.txtZIP.Text.Trim();
                customerInfo.Phone1 = this.txtPhone1.Text.Trim();
                customerInfo.Phone2 = this.txtPhone2.Text.Trim();
                customerInfo.Address = this.txtAddress.Text.Trim();
                customerInfo.Fax1 = this.txtFax1.Text.Trim();
                customerInfo.Fax2 = this.txtFax2.Text.Trim();
                customerInfo.Email1 = this.txtEmail1.Text.Trim();
                customerInfo.Email2 = this.txtEmail2.Text.Trim();
                if (this.chkSameAsAddress.Checked)
                {
                    customerInfo.BCity = customerInfo.City;
                    customerInfo.BState = customerInfo.State;
                    customerInfo.BContact1 = customerInfo.Contact1;
                    customerInfo.BContact2 = customerInfo.Contact2;
                    customerInfo.BCountry = customerInfo.Country;
                    customerInfo.BZip = customerInfo.Zip;
                    customerInfo.BPhone1 = customerInfo.Phone1;
                    customerInfo.BPhone2 = customerInfo.Phone2;
                    customerInfo.BAddress = customerInfo.Address;
                    customerInfo.BFax1 = customerInfo.Fax1;
                    customerInfo.BFax2 = customerInfo.Fax2;
                    customerInfo.BEmail1 = customerInfo.Email1;
                    customerInfo.BEmail2 = customerInfo.BEmail2;
                }
                else
                {
                    customerInfo.BCity = this.txtBillCity.Text.Trim();
                    customerInfo.BState = this.txtProvince.Text.Trim();
                    customerInfo.BContact1 = this.txtBillContact1.Text.Trim();
                    customerInfo.BContact2 = this.txtBillConatact2.Text.Trim();
                    customerInfo.BCountry = this.txtBillCountry.Text.Trim();
                    customerInfo.BZip = this.txtBillZIP.Text.Trim();
                    customerInfo.BPhone1 = this.txtBillPhone1.Text.Trim();
                    customerInfo.BPhone2 = this.txtBillPhone2.Text.Trim();
                    customerInfo.BAddress = this.txtBillAddress.Text.Trim();
                    customerInfo.BFax1 = this.txtBillFax1.Text.Trim();
                    customerInfo.BFax2 = this.txtBillFax2.Text.Trim();
                    customerInfo.BEmail1 = this.txtBillEmail1.Text.Trim();
                    customerInfo.BEmail2 = this.txtBillEmail2.Text.Trim();
                }
                customerInfo.Udf1 = this.txtUserDefine1.Text.Trim();
                customerInfo.Udf2 = this.txtUserDefine2.Text.Trim();
                customerInfo.Udf3 = this.txtUserDefine3.Text.Trim();
                customerInfo.Udf4 = this.txtUserDefine4.Text.Trim();
                customerInfo.Udf5 = this.txtUserDefine5.Text.Trim();
                customerInfo.Udf6 = this.txtUserDefine6.Text.Trim();
                customerInfo.Udf7 = this.txtUserDefine7.Text.Trim();
                customerInfo.Udf8 = this.txtUserDefine8.Text.Trim();
                customerInfo.Udf9 = this.txtUserDefine9.Text.Trim();
                customerInfo.Udf10 = this.txtUserDefine10.Text.Trim();
                customerInfo.Remark = this.txtRemark.Text.Trim();
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(customerInfo, "CUSTOMER") + base.GetGlobalMsgResource("C002");
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

